//
//  ZBMoBanThreeTbaleviewView.m
//  MoBan
//
//  Created by apple on 16/7/11.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZBMoBanThreeTbaleviewView.h"
#import "ZBMoBanIteamCell.h"
@interface ZBMoBanThreeTbaleviewView()
@property(nonatomic,strong)NSMutableArray *array;
@end
@implementation ZBMoBanThreeTbaleviewView
-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addUi];
    }
    return self;
}
-(void)addUi
{
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.array removeAllObjects];
    
    NSMutableArray *array = [self.datasouce ZBdatasouceIteams];
    
    for (NSInteger i=0; i<array.count; i++) {
        
        ZBMoBanIteamCell *cell = [[ZBMoBanIteamCell alloc]init];
        cell.tag = i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cellClic:)];
        [cell addGestureRecognizer:tap];
        [self addSubview:cell];
        [self.array addObject:cell];
        
    }
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    for (NSInteger i=0; i<self.array.count; i++) {
        ZBMoBanIteamCell *cell = self.array[i];
        
        if (self.array.count>2&&self.array.count<5) {
            cell.frame = CGRectMake((self.width/2)*(i%2), (self.height/2)*(i/2), self.width/2, self.height/2);
            
            NSLog(@"%@",NSStringFromCGRect(cell.frame));
            
        }else
        {
            cell.frame = CGRectMake((self.width/2)*(i%2), 0, self.width/2, self.height);
        
        }
    }
}
-(void)reloaddata
{

    [self addUi];
}
-(void)cellClic:(UIGestureRecognizer*)tap
{
    if ([self.deleget respondsToSelector:@selector(ZBCellClicIndex:)]) {
        [self.deleget ZBCellClicIndex:tap.view.tag];
    }

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
